/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package abricots.entity.collision;

import abricots.MyLog;
import abricots.entity.Entity;
import abricots.entity.ServerEntity;
import abricots.entity.state.BasicEntityState;
import abricots.entity.state.EntityState;
import abricots.entity.state.ServerEntityState;
import abricots.game.EntityFactory;
import abricots.game.GameConstants;
import com.esotericsoftware.minlog.Log;
import org.newdawn.slick.geom.Rectangle;
import org.newdawn.slick.geom.Shape;

/**
 *
 * @author charly
 */
public class ServerEntityCollisionManager implements EntityCollisionManager {
   public int longzss;
   protected int lososo;
   private Shape shape;
   private ServerEntity serverEntity;
   private final MyLog log = new MyLog(getClass().getSimpleName(), Log.LEVEL_TRACE);

   public ServerEntityCollisionManager(ServerEntity entity) {
      shape = new Rectangle(-10, -20, 20, 40);
      this.serverEntity = entity;
   }

   @Override
   public boolean isCollisionCheckNeeded(Entity other) {
      switch (other.getEntityTypeId()) {
         case GameConstants.ENTITY_TYPE_ID_BALL:
            return true;
      }
      return false;
   }

   @Override
   public Shape getCollisionShape(EntityState thisState) {
      BasicEntityState basicEntityState = (BasicEntityState) thisState;
      shape.setCenterX(basicEntityState.getPosX());
      shape.setCenterY(basicEntityState.getPosY());
      return shape;
   }

   @Override
   public void onCollision(Entity entity, long time) {
      ServerEntityState state = (ServerEntityState) serverEntity.getStateManager().getEntityState(time);
      state.setCollision(true);
      serverEntity.getStateManager().addState(state);
      log.trace("Collision set for " + time);
   }
}
